package cn.iocoder.yudao.module.custom.controller.admin.smsremind;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.custom.controller.admin.smsremind.vo.*;
import cn.iocoder.yudao.module.custom.dal.dataobject.smsremind.SmsRemindDO;
import cn.iocoder.yudao.module.custom.convert.smsremind.SmsRemindConvert;
import cn.iocoder.yudao.module.custom.service.smsremind.SmsRemindService;

@Tag(name = "管理后台 - 商户支付短信通知")
@RestController
@RequestMapping("/custom/sms-remind")
@Validated
public class SmsRemindController {

    @Resource
    private SmsRemindService smsRemindService;

    @PostMapping("/create")
    @Operation(summary = "创建商户支付短信通知")
    @PreAuthorize("@ss.hasPermission('custom:sms-remind:create')")
    public CommonResult<Integer> createSmsRemind(@Valid @RequestBody SmsRemindCreateReqVO createReqVO) {
        return success(smsRemindService.createSmsRemind(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新商户支付短信通知")
    @PreAuthorize("@ss.hasPermission('custom:sms-remind:update')")
    public CommonResult<Boolean> updateSmsRemind(@Valid @RequestBody SmsRemindUpdateReqVO updateReqVO) {
        smsRemindService.updateSmsRemind(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除商户支付短信通知")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('custom:sms-remind:delete')")
    public CommonResult<Boolean> deleteSmsRemind(@RequestParam("id") Integer id) {
        smsRemindService.deleteSmsRemind(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得商户支付短信通知")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('custom:sms-remind:query')")
    public CommonResult<SmsRemindRespVO> getSmsRemind(@RequestParam("id") Integer id) {
        SmsRemindDO smsRemind = smsRemindService.getSmsRemind(id);
        return success(SmsRemindConvert.INSTANCE.convert(smsRemind));
    }

    @GetMapping("/list")
    @Operation(summary = "获得商户支付短信通知列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('custom:sms-remind:query')")
    public CommonResult<List<SmsRemindRespVO>> getSmsRemindList(@RequestParam("ids") Collection<Integer> ids) {
        List<SmsRemindDO> list = smsRemindService.getSmsRemindList(ids);
        return success(SmsRemindConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得商户支付短信通知分页")
    @PreAuthorize("@ss.hasPermission('custom:sms-remind:query')")
    public CommonResult<PageResult<SmsRemindRespVO>> getSmsRemindPage(@Valid SmsRemindPageReqVO pageVO) {
        PageResult<SmsRemindDO> pageResult = smsRemindService.getSmsRemindPage(pageVO);
        return success(SmsRemindConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出商户支付短信通知 Excel")
    @PreAuthorize("@ss.hasPermission('custom:sms-remind:export')")
    @OperateLog(type = EXPORT)
    public void exportSmsRemindExcel(@Valid SmsRemindExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<SmsRemindDO> list = smsRemindService.getSmsRemindList(exportReqVO);
        // 导出 Excel
        List<SmsRemindExcelVO> datas = SmsRemindConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "商户支付短信通知.xls", "数据", SmsRemindExcelVO.class, datas);
    }

}
